package servlet;

import entity.Dept;
import entity.Emp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/empupdatenews")
public class EmpUpdateNewsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        int empno = Integer.parseInt(request.getParameter("empno"));
        String empname = request.getParameter("ename");
        String job = request.getParameter("job");
        Double sal = Double.parseDouble(request.getParameter("sal"));
        String dname = request.getParameter("dname");
        Dept dept=new Dept();
        dept.setDname(dname);
        Emp emp=new Emp();
        emp.setEmpno(empno);
        emp.setJob(job);
        emp.setSal(sal);
        emp.setDept(dept);
        emp.setEname(empname);
        HttpSession session=request.getSession();
        session.setAttribute("emp", emp);
        response.getWriter().print("true");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
